#include "config.h"
#include <common/settings.h>
#include <common/constants.h>

using namespace Constants;

ConfigDialog::ConfigDialog(QWidget * parent)
{
    setupUi(this);
    manageCombo();
    prepareEdits();
    connect(recordButton,SIGNAL(pressed()),this,SLOT(accept()));
    connect(cancelButton,SIGNAL(pressed()),this,SLOT(reject()));
     
}

ConfigDialog::~ConfigDialog(){}

void ConfigDialog::manageCombo()
{
    QStringList list;
    list << "no" << "yes";
    yesNoBox->addItems(list);
    QStringList listprograms;
    listprograms << "none" << "medintux" << "medintux-inside";
    programBox->addItems(listprograms);
}

void ConfigDialog::prepareEdits()
{
    settings set(this);
    QString localhost = set.value(HOST_DRTUX).toString();
    QString user = set.value(USER_DRTUX).toString();
    QString password = set.value(PASSWORD_DRTUX).toString();
    QString port = set.value(PORT_DRTUX).toString();
   
    hostEdit->setText(localhost);
    userEdit->setText(user);
    passwordEdit->setText(password);
    portEdit->setText(port);
}

void ConfigDialog::record()
{
    settings set(this);
    set.setValue(CALLING_PROGRAM,programBox->currentText());
    set.setValue(FIRSTTIME,yesNoBox->currentText());
    set.setValue(HOST_DRTUX,hostEdit->text());
    set.setValue(USER_DRTUX,userEdit->text());
    set.setValue(PASSWORD_DRTUX,passwordEdit->text());
    set.setValue(PORT_DRTUX,portEdit->text());
}


